<?php

use Phinx\Migration\AbstractMigration;
use Phinx\Db\Adapter\MysqlAdapter;

class CreateTenantProdCapacityTable extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    addCustomColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Any other destructive changes will result in an error when trying to
     * rollback the migration.
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('tenant_prod_capacity', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '租户用户产能表']);

        //添加数据字段
        $table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('tenant_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '所属租户id'])
            ->addColumn('type', 'enum', ['values' => 'inside,outside', 'default' => 'inside', 'comment' => '产能类型，内部还是外部产能'])
            ->addColumn('user_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '所属用户id，外部设置联系人id'])
            ->addColumn('step_category_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '所属工序分类id'])
            ->addColumn('level_category', 'enum', ['values' => 's,a,b,c', 'default' => 'c', 'comment' => '所属级别分类'])
            ->addColumn('date', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '所在日期（记录时间戳）'])
            ->addColumn('capacity', 'integer', ['default' => 0, 'limit' => MysqlAdapter::INT_TINY, 'comment' => '剩余产能，单位小时，不能超过24小时']);

        //执行创建
        $table->create();
    }
}
